package de.web.scheduler;

import de.preisrobot.service.ImageGrabberService;

public class ImageScheduler {

	private static ImageScheduler inst;

	private ImageGrabberService imageService;

	private ImageScheduler() {
		Thread t = new Thread(new Runnable() {

			@Override
			public void run() {

				while (true) {

					grapImages();
					
					try {
						Thread.sleep(2 * 60 * 1000);
					} catch (InterruptedException e) {

						e.printStackTrace();
					}
					
				}
			}
		});

		t.start();
	}

	public static ImageScheduler getInstance() {
		if (inst == null)
			inst = new ImageScheduler();

		return inst;
	}

	private void grapImages() {
		if (this.imageService != null)
			imageService.grabImages();
	}

	public void setImageService(ImageGrabberService imageService) {
		this.imageService = imageService;
	}

}
